//
// Created by DELL on 2022/4/18.
//
#pragma once

#include "../Utils.h"
#include "../VulkanDefine.h"

BEGIN_NS_VULKAN

class Context
{
public:
#ifdef _DEBUG
   static constexpr bool enable_validation_Layers  = true;
#else
    static constexpr bool enable_validation_Layers  = false;
#endif

    Context(const Context&) = delete;
    Context& operator=(Context&) = delete;

    static Context* get()
    {
        static Context instance;
        return &instance;
    }

    void initialize(HWND hwnd);
    void unInitialize();

    VkInstance getInstance() const { return instance; }
    VkSurfaceKHR getSurface() const { return surface; }

    void populateDebugMessengerCreateInfo(VkDebugUtilsMessengerCreateInfoEXT& createInfo);
    const std::vector<const char*> validation_layers {"VK_LAYER_KHRONOS_validation"};

private:

    Context() = default;
    ~Context() = default;
    void createInstance();
    void setupDebugMessenger();
    void createSurface(HWND hwnd);

    bool checkValidationLayerSupport();
    std::vector<const char*> getRequiredExtensions();
    void destroyDebugUtilsMessenger();

    uint32_t vulkan_api_version = VK_MAKE_API_VERSION(0, 1, 2, 0);

    VkInstance instance {VK_NULL_HANDLE};
    VkSurfaceKHR surface {VK_NULL_HANDLE};
    VkDebugUtilsMessengerEXT debugMessenger {VK_NULL_HANDLE};
};

END_NS_VULKAN
